package org.gukewen.controller;

import jakarta.annotation.Resource;
import org.gukewen.order.bean.Order;
import org.gukewen.properties.OrderProperties;
import org.gukewen.service.OrderService;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope
@RestController
public class OrderController {

    @Resource
    private OrderService orderService;

//    @Value("${order.name}")
//    private String name;

    @Resource
    private OrderProperties orderProperties;

    @GetMapping("/create")
    public Order createOrder(@RequestParam("userId") Long userId, @RequestParam("productId") Long productId){
        Order order = orderService.createOrder(userId, productId);
        return order;
    }

    @GetMapping("/config")
    public String getConfig(){
        return orderProperties.getName() + ":" + orderProperties.getAge();
    }
}
